/**
 * Project Name:springBoot-serviceImpl
 * File Name:TestThreadPoolUtils.java
 * Package Name:com.libra.utils.concurrent
 * Date:2018年10月17日下午3:31:29
 * Copyright (c) 2018, wangzhch All Rights Reserved.
 *
*/

package com.libra.utils.concurrent;

import java.util.Random;

/**
 * ClassName:测试线程池的工具类 <br/>
 * Date:     2018年10月17日 下午3:31:29 <br/>
 * @author   wangzhch
 * @version  
 * @since    JDK 1.8
 * @see 	 
 */
public class TestThreadPoolUtils {
	public static void main(String[] args) throws InterruptedException {
		//创建三个线程的线程池,这里的队列个数等于0时，实际使用的是他的默认值
		ThreadPoolUtils poolUtils = new ThreadPoolUtils(3, 0);
		poolUtils.execute(new MyTask("testA"));
		poolUtils.execute(new MyTask("testB"));
		poolUtils.execute(new MyTask("testC"));
		poolUtils.execute(new MyTask("testD"));
		poolUtils.execute(new MyTask("testE"));
		System.out.println("打印："+poolUtils);
		Thread.sleep(10000);
		poolUtils.destroy();
		System.out.println("销毁后:"+poolUtils);
	}
	
	public static class MyTask implements Runnable{

		private String name;
		
		public MyTask(String name) {
			this.name=name;
		}
		
		@Override
		public void run() {
			try {
				Thread.sleep(new Random().nextInt(1000)+2000);
			} catch (InterruptedException e) {
				System.out.println(Thread.currentThread().getId()+" sleep InterruptedException:" + Thread.currentThread().isInterrupted());
			}
			System.out.println("任务："+name+"已完成");
		}
		
	}
}

